package com.fbli.controller;

import com.fbli.entity.Result;
import com.fbli.pojo.GoodsOrder;
import com.fbli.pojo.Knowledge;
import com.fbli.service.GoodsOrderService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goodsOrder")
public class GoodsOrderController {
    @Autowired
    private GoodsOrderService goodsOrderService;
    @RequestMapping("/selectPage")
    public PageInfo<GoodsOrder> selectPage(@RequestBody GoodsOrder goodsOrder, int pageNum, int pageSize){
        System.out.println(goodsOrderService.selectPage(goodsOrder,pageNum,pageSize));
        return goodsOrderService.selectPage(goodsOrder,pageNum,pageSize);

    }
    @RequestMapping("/insert")
    public Result insert(@RequestBody GoodsOrder record){
        System.out.println("insertController");
        try {
            goodsOrderService.insert(record);
            return new Result(true,"成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"异常，失败");
        }
    }
    @RequestMapping("/deleteByPrimaryKey")
    public Result deleteByPrimaryKey(long[] orderids){
        System.out.println("deleteByPrimaryKey+controller"+orderids);
        try {
            goodsOrderService.deleteByPrimaryKey(orderids);
            return new Result(true,"成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"异常，失败");
        }
    }

    @RequestMapping("/updateByPrimaryKey")
    public Result updateByPrimaryKey(@RequestBody GoodsOrder record){

        try {
            goodsOrderService.updateByPrimaryKey(record);
            return new Result(true,"成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"异常，失败");
        }
    }
    @RequestMapping("/selectByPrimaryKey")
    public GoodsOrder selectByPrimaryKey(int orderid){
        return goodsOrderService.selectByPrimaryKey(orderid);
    }
    @RequestMapping("/selectAll")
    public Result selectAll(){
        try {
            goodsOrderService.selectAll();
            return new Result(true,"成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"异常，失败");
        }
    }
    @RequestMapping("/selectOrder")
    public Result selectOrder(String keyword){
        try {
            goodsOrderService.selectOrder(keyword);
            return new Result(true,"成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"异常，失败");
        }
    }
    /*@RequestMapping("/selectId")
    public int selectId(int itemId){
        return goodsOrderService.selectId(itemId);
    }*/
}
